package com.zhangpingyang.springcloud.userservice.controller;

import com.zhangpingyang.springcloud.userservice.domain.CommonResult;
import com.zhangpingyang.springcloud.userservice.domain.User;
import com.zhangpingyang.springcloud.userservice.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Zhang Pingyang
 * @Date: 2019/11/27 15:40
 */
@RestController
@RequestMapping(value = "user")
public class UserController {
    //    private Log LOGGER = LoggerFactory.getLogger(this.getClass());
    private Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;

    @PostMapping("/create")
    public CommonResult create(@RequestBody User user) {
        userService.create(user);
        return new CommonResult("草暂存过", 200);
    }

    @GetMapping("/{id}")
    public CommonResult<User> getUser(@PathVariable Long id) {
        User user = userService.getUser(id);
        LOGGER.info("根据id获取用户信息，用户名称为：{}",user.getUsername());
        return new CommonResult<>(user);
    }
}

